package com.gr.jron.service;

import org.acegisecurity.userdetails.UsernameNotFoundException;
import com.gr.jron.dao.UserDao;
import com.gr.jron.model.*;

import java.util.List;

import net.sf.json.JSONObject;


/**
 * Business Service Interface to handle communication between web and
 * persistence layer.
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 *         Modified by <a href="mailto:dan@getrolling.com">Dan Kibler </a>
 */
public interface UserManager extends UniversalManager {

    /**
     * Convenience method for testing - allows you to mock the DAO and set it on an interface.
     *
     * @param userDao the UserDao implementation to use
     */
    void setUserDao(UserDao userDao);

    /**
     * Retrieves a user by userId.  An exception is thrown if user not found
     *
     * @param userId the identifier for the user
     * @return User
     */
    User getUser(String userId);

    /**
     * Finds a user by their username.
     *
     * @param username the user's username used to login
     * @return User a populated user object
     * @throws org.acegisecurity.userdetails.UsernameNotFoundException
     *          exception thrown when user not found
     */
    User getUserByUsername(String username) throws UsernameNotFoundException;

    User getUserByName(String username);

    /**
     * Retrieves a list of users, filtering with parameters on a user object
     *
     * @param user parameters to filter on
     * @return List
     */
    List getUsers(User user);

    /**
     * Saves a user's information
     *
     * @param user the user's information
     * @return user the updated user object
     * @throws UserExistsException thrown when user already exists
     */
    User saveUser(User user) throws UserExistsException;

    /**
     * Removes a user from the database by their userId
     *
     * @param userId the user's id
     */
    void removeUser(String userId);

    JSONObject getJsonUsersPerPage(PagingQuery pq);

    JSONObject getJsonUser(String id);

    User saveUser(User user, UgGovermentInfo govermentInfo) throws UserExistsException;

    User saveUser(User user, UgTeamInfo teamInfo) throws UserExistsException;

    User saveUser(User user, UgPersonInfo personInfo) throws UserExistsException;

    User saveUser(User user, UgCompanyInfo companyInfo) throws UserExistsException;

    User getUserByEmail(String email);
}
